Keyword Reference

ExitLoop

Terminate a While/Do/For loop.

ExitLoop [level]

 

Parameters

level [optional] The number of loop levels to exit from. The default is 1 (meaning the current loop).

 

Remarks

A negative level or zero value has no effect.

ExitLoop will break out of a While, Do or For loop.
ExitLoop is useful when you would otherwise need to perform error checking in both the loop-test and the loop-body.

 

Related

ContinueLoop, Exit, For, Do, While

 

Example


$sum = 0
While 1 ;use infinite loop since ExitLoop will get called
    $ans = InputBox("Running total=" & $sum, _
        "   Enter a positive number.  (A negative number exits)")
    If $ans < 0 Then ExitLoop
    $sum = $sum + $ans
WEnd
MsgBox(0,"The sum was", $sum)